﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis.Options;
using Microsoft.Extensions.Options;
using net8.Models;
using net8.Models.Wangzhan;
using System.Text.Json;

namespace net8.Controllers.Wangzhan
{
    /// <summary>
    /// 消息管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class WZNewsController : ControllerBase
    {
        private readonly ILogger _logger;
        public WZNewsController(ILogger<WZNews> logger)
        {
            _logger = logger;
        }

        /// <summary>
        /// 程序数据
        /// </summary>
        [HttpGet]
        public List<WZNews> GetList()
        {
            return DbHelper.Db.Queryable<WZNews>().ToList();
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        /// <param name="model">消息模型</param>
        [HttpPost]
        [AllowAnonymous]
        public void Save([FromBody] WZNews model)
        {
            DbHelper.Db.Storageable(model).ExecuteCommand();
        }

        [HttpGet]
        [AllowAnonymous]
        public Dictionary<string, string[]> GetKeys()
        {
            Dictionary<string, string[]> aaa = new Dictionary<string, string[]>();
            aaa.Add("Title", ["11", "22"]);

            _logger.LogInformation("日志测试");
            return aaa;
        }

        [HttpGet]
        [AllowAnonymous]
        public void GetTests()
        {
            List<WZNews> list = new List<WZNews>();
            for (int i = 0; i < 10; i++)
            {
                list.Add(new WZNews
                {
                    Id = Guid.NewGuid(),
                    IsDel = false,
                    AddTime = DateTime.Now,
                    UpdateTime = DateTime.Now,
                    Author = "作者1",
                    Content = "",
                    ImageUrl = "",
                    Title = ""
                });
            }
        }
    }
}
